-
Notifications
You must be signed in to change notification settings - Fork 48
feat: Adds support for providing default URL parameters via the frontend #75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Adds support for providing default URL parameters via the frontend #75
Conversation
9a3deb4
to
722e0fc
Compare
722e0fc
to
5ed96ae
Compare
Nice work @owenconti - excited for this one! |
Ok, this looks cool, thanks! Couple of adjustments/notes:
Going to merge this in with the caveat that with the new Wayfinder changes coming down the pipeline in the next month or so these might change, just a heads up. |
Thank you for getting to this @joetannenbaum! |
Of course! Thanks for your patience. |
Couldn't make it work.. Need to define locale value for the routes.. I think It's not possible to define default locale value for this right now. we need to define a dynamic prefix value like this.. https://github.com/mcamara/laravel-localization/?tab=readme-ov-file#usage Route::group(
[
'prefix' => LaravelLocalization::setLocale(),
'middleware' => [ 'localeSessionRedirect', 'localizationRedirect', 'localeViewPath' ]
], function(){ //...
}); |
This should resolve #49
This PR adds support for providing default URL values during runtime via the frontend. This works by providing methods within the
wayfinder.ts
that user-land code can call to set (or add individual) default parameters. These parameters are stored in a globalWayfinder
window object.When generating the URL for a controller, we merge in any set default parameters, making sure that we don't override any keys already set during the calling of the
url
method.Note: in theory we don't need to use a window object here, but when running the test suite, it seems like I was getting different instances of the
wayfinder.ts
file, the default parameters that were set were getting lost.Usage
Here's how I have it set up in our app. The benefit here is it is up to the user to decide where and when to apply the defaults:
One thing I have not figured out with this approach is non-optional parameters that do not have a default set via the URL facade on the backend. Wayfinder doesn't know that
domain
parameter is being set as a default and will be applied/set during theurl()
call: